# To change this template, choose Tools | Templates
# and open the template in the editor.

class Student
  def initialize(class_path)
    @students_path = class_path
  end
  def get_students_lines
    students_list = File.open(@students_path, 'r')
    students_lines = students_list.readlines()
    students_list.close
    students_lines
  end
  def find_new_name(file_name)
    students_lines = get_students_lines
    new_name = nil
    students_lines.each{ |student_line|
      students_info = student_line.split(",")
      student_serial, student_no, student_name = students_info[0], students_info[1], students_info[2]
      if (student_serial.to_i >= 1 && student_serial.to_i < 100)
        file_names = file_name.split(".")
        file_ext = (file_names.length == 1)? "" : file_names[file_names.length-1]
        if (file_name.include?(student_no) || file_name.include?(student_name))
          new_name = student_no + student_name + ((file_ext.empty?)? "" : ".") + file_ext
        end
      end
    }
    return new_name
  end
end
